#!/bin/sh
# PDFedit - free program for PDF document manipulation.
# Copyright (C) 2006-2009  PDFedit team: Michal Hocko,
#                                        Jozef Misutka,
#                                        Martin Petricek
#                   Former team members: Miroslav Jahoda
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program (in doc/LICENSE.GPL); if not, write to the 
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA  02111-1307  USA
#
# Project is hosted on http://sourceforge.net/projects/pdfedit

# This is script that will create distribution tarballs

# Checks for configure script and generates it if either
# existing one is older than configure.in or it doesn't exist at all
AUTOCONF="`which autoconf`"
if [ ! -x configure -o configure -ot configure.in ]
then
	if [ ! -x $AUTOCONF ]
	then
		echo Autoconf not found.
		exit 1
	fi
	echo Generating configure script
	RESULT=OK
	$AUTOCONF || RESULT=FAILED
	echo $RESULT
	if [ "$RESULT" = "FAILED" ]
	then
		echo Unable to generate configure script
		exit 1
	fi
fi
# generates online help
tools/generate_online_help.sh doc src/gui
echo Online help generated

# generates man page
cd doc/tools/
./docbook2man.pl ../user/pdfedit.xml > ../user/pdfedit.1
cd ../../
echo Man page generated

#Get version number
VERSION=`./getversion -v -r`
GENERATED_FILES=".scmversion configure doc src/gui doc/user/pdfedit.1"

TAR_PREFIX="pdfedit-$VERSION/"
TAR_FILE="pdfedit-${VERSION}.tar"

# Git archive makes it really hard to exclude file (.gitattributes
# and export-ignore is really awkward) so do not try to use it and
# just pipe all tracked files directly to tar
# Make sure all files show up in the TAR_PREFIX subdir
git ls-tree -rz --name-only HEAD | xargs -0 tar --exclude-from=dist-exclude --transform "s@^@$TAR_PREFIX/@" -cf $TAR_FILE 

# Add untracked (generated) files as well
echo $VERSION > .scmversion
tar --exclude-from=dist-exclude --transform "s@^@$TAR_PREFIX/@" -rf $TAR_FILE $GENERATED_FILES
rm .scmversion

gzip "pdfedit-${VERSION}.tar"
